<template>
	<el-switch
		v-model="datas"
		active-color="#13ce66"
		inactive-color="#ff4949"
		@change="userState"
	>
	</el-switch>
</template>
<script>
export default {
	name: 'Switchs',
	props: ['data'],
	data() {
		return {
			datas: this.data.type,
			uId: this.data.uld,
		}
	},
	methods: {
		userState(val) {
			this.$http
				.put(`/users/${this.uId}/state/${val}`)
				.then(response => {
					const { meta } = response.data
					if (meta.status != 200) {
						this.$message.error(meta.msg)
						this.datas = !this.datas
						return
					}
					this.$message({
						message: '修改成功！',
						type: 'success',
						duration: '700',
					})
				})
				.catch(error => {
					console.log(error.message)
				})
		},
	},
}
</script>
